import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/appbar/base_app_bar.dart';
import 'package:xvideos/tools_base/loading/loading_center_widget.dart';
import 'package:xvideos/tools_base/refresh/pull_refresh.dart';
import '../../../hj_model/message/search_user_obj.dart';
import '../../../routers/jump_router.dart';
import '../../../tools_base/image/custom_network_image.dart';
import '../../../tools_base/loading/l_error_widget.dart';
import '../../../tools_base/widget/net_image_widget.dart';
import 'hot_up_list_logic.dart';

class HotUpListPage extends StatelessWidget {
  const HotUpListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BaseAppBar(title: "热门博主"),
      body: GetBuilder<HotUpListLogic>(
        init: HotUpListLogic(),
        global: false,
        builder: (logic) {
          if (logic.isLoading) {
            return LoadingCenterWidget();
          } else if (logic.dataSource.isEmpty) {
            return CErrorWidget(
              retryOnTap: () => logic.fetchPagedata(),
            );
          } else {
            return Container(
              child: pullYsRefresh(
                onInit: (ctr) => logic.refreshController = ctr,
                onRefresh: (_) => logic.fetchPagedata(),
                onLoading: (_) => logic.loadMoreData(),
                child: ListView.builder(
                  padding: EdgeInsets.only(top: 12),
                  itemCount: logic.dataSource.length,
                  itemBuilder: (BuildContext context, int index) {
                    HotBloggerEntity model = logic.dataSource[index];
                    return _buildUpItem(model);
                  },
                ),
              ),
            );
          }
        },
      ),
    );
  }

  Widget _buildUpItem(HotBloggerEntity model) {
    return Container(
      margin: EdgeInsets.fromLTRB(16, 0, 16, 12),
      width: 52,
      child: InkWell(
        onTap: () {
          pushToPersonCenter(model.uid);
        },
        child: Row(
          children: [
            NetworkImageLoader(
              imageUrl: model.portrait ?? '',
              width: 52,
              height: 52,
              loadWidth: 52 * 3,
              borderRadius: 30,
            ),
            12.sizeBoxW,
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    model.name ?? "",
                    maxLines: 1,
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.white,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  2.sizeBoxH,
                  Text(
                    "作品数: ${model.totalWork}",
                    maxLines: 1,
                    style: TextStyle(
                      fontSize: 12,
                      color: Color(0xffE0E0E0),
                    ),
                  ),
                ],
              ),
            ),
            10.sizeBoxW,
            Image.asset("arrow_right_grey.webp".commonImgPath, width: 24),
          ],
        ),
      ),
    );
  }
}
